import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_ohos/components/MTBody.dart';
import 'MTBottom.dart';
import 'MTTop.dart';
import 'MTBody.dart';

class MTMain extends StatefulWidget {
  const MTMain({Key? key}) : super(key: key);

  @override
  _MTMainState createState() => _MTMainState();
}

class _MTMainState extends State<MTMain> {
  List _foodList = []; //接收列表数据
  @override
  void initState() {
    // TODO: implement initState
    getFoodData();
    super.initState();
  }

  getFoodData() async {
    Dio dio = Dio();
    var res = await dio
        .get('https://zhousg.atomgit.net/harmonyos-next/takeaway.json');
    setState(() {
      _foodList = res.data as List; //数据更新
      print(_foodList[0]['name']);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      alignment: Alignment.bottomCenter,
      children: [
        Container(
          width: double.infinity,
          height: double.infinity,
          color: const Color.fromARGB(255, 128, 91, 104),
          child: Column(
            children: [
              MTTop(),
              Expanded(
                child: MTBody(
                  // 父传子传递参数
                  list: _foodList,
                ),
                flex: 1,
              )
            ],
          ),
        ),
        const MTBottom(),
      ],
    );
  }
}
